package org.michaelrenaud.pathfinder.client.core.app.combat;

import org.michaelrenaud.pathfinder.shared.model.Character;
import org.michaelrenaud.pathfinder.shared.model.StatBlock;

import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Label;

public class CombatView extends ViewImpl implements CombatPresenter.MyView {

	@UiField Label txtInit;
	@UiField Label txtInitModifier;
	@UiField Label txtInitFeat;
	@UiField Label txtInitTraining;
	@UiField Label txtInitMisc;
	@UiField Label txtLandMA;
	@UiField Label txtLandSq;
	@UiField Label txtLandH;
	@UiField Label txtLandD;
	@UiField Label txtFlyMA;
	@UiField Label txtFlySq;
	@UiField Label txtFlyH;
	@UiField Label txtFlyD;
	@UiField Label txtSwimMA;
	@UiField Label txtSwimSq;
	@UiField Label txtSwimH;
	@UiField Label txtSwimD;
	@UiField Label txtClimbMA;
	@UiField Label txtClimbSq;
	@UiField Label txtClimbH;
	@UiField Label txtClimbD;
	@UiField Label txtMountMA;
	@UiField Label txtMountSq;
	@UiField Label txtMountH;
	@UiField Label txtMountD;
	private final Widget widget;
	
	private Character character;
	private StatBlock statBlock;

	public interface Binder extends UiBinder<Widget, CombatView> {}

	@Inject
	public CombatView(final Binder binder) {
		widget = binder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setCharacter(Character character, StatBlock statBlock) {
		this.character = character;
		this.statBlock = statBlock;
		displayCharacter();
	}

	private void displayCharacter() {
		// Init
		txtInit.setText(statBlock.getInit() + "");
		txtInitModifier.setText(statBlock.getDEX() + "");
		txtInitModifier.setTitle("DEX");
		txtInitFeat.setText(statBlock.getInitFeat().getTotal() + "");
		txtInitFeat.setTitle(statBlock.getInitFeat().getTooltip());
		txtInitTraining.setText(statBlock.getInitTraining().getTotal() + "");
		txtInitTraining.setTitle(statBlock.getInitTraining().getTooltip());
		txtInitMisc.setText(statBlock.getInitMisc().getTotal() + "");
		txtInitMisc.setTitle(statBlock.getInitMisc().getTooltip());
		
		// Speeds
		initSpeed();
		if(statBlock.getBaseSpeed() != 0) {
			txtLandMA.setText(statBlock.getBaseSpeed() + " ft");
			txtLandSq.setText(statBlock.getBaseSpeed() / 5 + " sq");
			txtLandH.setText(statBlock.getBaseSpeed() / 10 + " mi");
			txtLandD.setText(statBlock.getBaseSpeed() * 8 / 10 + " mi");
		}
		
		if(statBlock.getFlySpeed() != 0) {
			txtFlyMA.setText(statBlock.getFlySpeed() + " ft");
			txtFlySq.setText(statBlock.getFlySpeed() / 5 + " sq");
			txtFlyH.setText(statBlock.getFlySpeed() / 10 + " mi");
			txtFlyD.setText(statBlock.getFlySpeed() * 8 / 10 + " mi");
		}
		
		if(statBlock.getSwimSpeed() != 0) {
			txtSwimMA.setText(statBlock.getSwimSpeed() + " ft");
			txtSwimSq.setText(statBlock.getSwimSpeed() / 5 + " sq");
			txtSwimH.setText(statBlock.getSwimSpeed() / 10 + " mi");
			txtSwimD.setText(statBlock.getSwimSpeed() * 8 / 10 + " mi");
		}
		
		if(statBlock.getClimbSpeed() != 0) {
			txtClimbMA.setText(statBlock.getClimbSpeed() + " ft");
			txtClimbSq.setText(statBlock.getClimbSpeed() / 5 + " sq");
			txtClimbH.setText(statBlock.getClimbSpeed() / 10 + " mi");
			txtClimbD.setText(statBlock.getClimbSpeed() * 8 / 10 + " mi");
		}
		
		if(statBlock.getMountSpeed() != 0) {
			txtMountMA.setText(statBlock.getMountSpeed() + " ft");
			txtMountSq.setText(statBlock.getMountSpeed() / 5 + " sq");
			txtMountH.setText(statBlock.getMountSpeed() / 10 + " mi");
			txtMountD.setText(statBlock.getMountSpeed() * 8 / 10 + " mi");
		}
	}
	
	private void initSpeed() {
		txtLandMA.setText("-");
		txtLandSq.setText("-");
		txtLandH.setText("-");
		txtLandD.setText("-");
		
		txtFlyMA.setText("-");
		txtFlySq.setText("-");
		txtFlyH.setText("-");
		txtFlyD.setText("-");
		
		txtSwimMA.setText("-");
		txtSwimSq.setText("-");
		txtSwimH.setText("-");
		txtSwimD.setText("-");
		
		txtClimbMA.setText("-");
		txtClimbSq.setText("-");
		txtClimbH.setText("-");
		txtClimbD.setText("-");
		
		txtMountMA.setText("-");
		txtMountSq.setText("-");
		txtMountH.setText("-");
		txtMountD.setText("-");
	}
}
